﻿using System.Web.Mvc;

namespace MsForgeReboot.Web.Controllers
{
    using MsForgeReboot.Framework.Entities;
    using MsForgeReboot.Framework.Interfaces;

    using PagedList;

    public class BlogController : Controller
    {
        private readonly IBlogService blogService;

        public BlogController(IBlogService blogService) {
            this.blogService = blogService;
        }

        [HttpGet]
        public ActionResult Index(int page = 1, int pageSize = 10){
            ViewBag.Title = "Blog Posts";
            return this.View(this.blogService.GetList(page, pageSize));
        }

        [HttpGet]
        public ActionResult Post(string urlPointer)
        {
            return this.View(this.blogService.GetByUrlPointer(urlPointer));
        }

        [HttpGet]
        public ActionResult Tag(string urlPointer, int page = 1, int pageSize = 10)
        {
            var tag = this.blogService.GetTag(urlPointer);
            ViewBag.Title = tag.Name;

            return this.View("Index", this.blogService.GetListByTag(tag.Name, page, pageSize));
        }

        [HttpPost]
        public ActionResult PostComment(Comment model)
        {
            return this.PartialView("_comment", model);
        }
    }
}
